package com.hzw.saas.api.template.enums;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.hzw.saas.api.template.util.TemplateUtil;

/**
 * 项目申请模板key
 *
 * @author zzl
 * @since 09/06/2021
 */
public enum TemplateTypeKeyEnum {

    //// 项目申请
    PROJECT_APPLY_ID("projectApplyId", TemplateTypeEnum.PROJECT_APPLY.getType(), "项目申请ID"),
    PROJECT_APPLY_FLOW_INSTANCE_ID("flowInstanceId", TemplateTypeEnum.PROJECT_APPLY.getType(), "项目申请流程ID"),
    PROJECT_APPLY_USER_NAME("username", TemplateTypeEnum.PROJECT_APPLY.getType(), "申请人用户名"),
    PROJECT_APPLY_REAL_NAME("realName", TemplateTypeEnum.PROJECT_APPLY.getType(), "申请人真实姓名"),
    PROJECT_APPLY_PHONE("phone", TemplateTypeEnum.PROJECT_APPLY.getType(), "申请人手机号"),
    PROJECT_APPLY_EMAIL("email", TemplateTypeEnum.PROJECT_APPLY.getType(), "申请人邮箱"),
    PROJECT_APPLY_PROJECT_NAME("projectName", TemplateTypeEnum.PROJECT_APPLY.getType(), "审批项目名称"),
    PROJECT_APPLY_FLOW_NODE("flowNode", TemplateTypeEnum.PROJECT_APPLY.getType(), "审批流程当前节点/状态，如审批中，审批回退等"),
    PROJECT_APPLY_LATEST_SUGGESTION("latestSuggestion", TemplateTypeEnum.PROJECT_APPLY.getType(), "审批流程当前节点/状态的审批意见"),
    CURRENT_DATE("date", TemplateTypeEnum.PROJECT_APPLY.getType(), "当前时间，支持pattern，如{{date[yyyy-MM-dd]}}; {{date}}使用默认格式yyyy-MM-dd HH:mm:ss"),

    ;

    private final String originKey;
    private final String key;
    private final Integer type;
    private final String text;

    TemplateTypeKeyEnum(String originKey, Integer type, String text) {
        this.originKey = originKey;
        this.key = TemplateUtil.formatKey(originKey);
        this.type = type;
        this.text = text;
    }

    public String getOriginKey() {
        return originKey;
    }

    public String getKey() {
        return key;
    }

    public Integer getType() {
        return type;
    }

    public String getText() {
        return text;
    }

    public static List<TemplateTypeKeyEnum> listInstance(Integer type) {
        List<TemplateTypeKeyEnum> result = new ArrayList<>();
        for (TemplateTypeKeyEnum value : TemplateTypeKeyEnum.values()) {
            if (Objects.equals(value.getType(), type)) {
                result.add(value);
            }
        }
        return result;
    }

}
